package com.zixue.heima.helloNetty.EventLoopGroopDemo;

import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName : HelloEventLoopGroup
 * @Description : TODO
 * @Author : chunxiong
 * @Date : 2025/5/3 22:50
 * @Version 1.0
 */
@Slf4j
public class HelloEventLoopGroup {
    public static void main(String[] args) {
        //1.创建事件循环组
        EventLoopGroup elg = new NioEventLoopGroup(2);  //io事件 普通任务 定时任务
//        EventLoopGroup elg2 = new DefaultEventLoop(); //处理普通任务 定时任务
        EventLoop next = elg.next();
        System.out.println(next);
        System.out.println(elg.next());
        System.out.println(elg.next());

        //执行普通任务
        elg.next().submit(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("ok");
        });

        //定时任务
        elg.next().scheduleAtFixedRate(()->{
            log.debug("ok");
        },4,1, TimeUnit.SECONDS);
    }
}
